#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T,n;
bool flg[N];
int a[N];
long long ans=0;
int maxx(long long x,int y){
    return x>y?x:y;
}
void f(int x,int c){
    if(x>n){
        ans=maxx(ans,c);
        return;
    }
    flg[x]=1;
    bool fl=0;
    for(int i=x;i>=1;i--){
        if(flg[i]==flg[x]){
            fl=1;
            if(a[i]==a[x]){
                f(x+1,c+a[i]);
            }else f(x+1,c);
            break;
        }
    }
    if(!fl)f(x+1,c);
    flg[x]=0;
    fl=0;
    for(int i=x;i>=1;i--){
        if(flg[i]==flg[x]){
            fl=1;
            if(a[i]==a[x]){
                f(x+1,c+a[i]);
            }else f(x+1,c);
            break;
        }
    }
    if(!fl)f(x+1,c);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        memset(flg,0,sizeof(flg));
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        f(1,0);
        cout<<ans;
    }
    return 0;
}

